<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Home\Controller;
use OT\DataDictionary;

/**
 * 前台首页控制器
 * 主要获取首页聚合数据
 */
class IndexController extends HomeController {

	/*系统首页*/
    public function index(){
        $meta=array(
            'meta_title'=>C("WEB_SITE_TITLE"),
            'keywords'  =>C("WEB_SITE_KEYWORD"),
            'description'=>C("WEB_SITE_DESCRIPTION"),
            'template_index'=>"Index/index",
        );
        $community_detail =session("community_detail");
        $this->assign("meta",$meta);
        /*首页大图*/

        /*大菜单*/
        $cate_list = $this->category->getTree();
        $this->assign("cate_list",$cate_list);
        /*通知公告*/
        $notification_map =[
            'ot_document_article.community_ids'=>array("like",'%'.$community_detail['id'].'%'),
            'ot_document.status' =>1,
            'ot_document.pid' => 0,
            'ot_document.category_id' =>155
        ];
        $document = M("document");
        $notification_lists = $document->join("ot_document_article on ot_document.id =ot_document_article.id")->field("ot_document.id,ot_document.title")->where($notification_map)->order("level desc,id desc")->select();
        //print_r($notification_lists);exit;
        $this->assign("notification_lists",$notification_lists);
        //四个小分类
        $c_list[0] = $this->category->getTree(49);
        $c_list[1] = $this->category->getTree(170);
        $this->assign("c_list",$c_list);
        //附近捡趴活，社区活动
        $article_list = $this->category->getTree(49);
        $ph_map = [
            'ot_document_merchant.community_ids'=>array("like",'%'.$community_detail['id'].'%'),
            'ot_document.status' =>1,
            'ot_document.pid' => 0,
            'ot_document.category_id' =>118
        ];
        $ho_map = [
            'ot_document_merchant.community_ids'=>array("like",'%'.$community_detail['id'].'%'),
            'ot_document.status' =>1,
            'ot_document.pid' => 0,
            'ot_document.category_id' =>141
        ];
        $shop_map = [
            'ot_document_article.community_ids'=>array("like",'%'.$community_detail['id'].'%'),
            'ot_document.status' =>1,
            'ot_document.pid' => 0,
            'ot_document.category_id' =>201
        ];
        $art_list[0] = $document->join("ot_document_merchant on ot_document.id =ot_document_merchant.id")->field("ot_document.id,ot_document.title,ot_document.cover_id,ot_document.category_id,ot_document.create_time")->where($ph_map)->limit(6)->order("level desc,id desc")->select();//附近捡趴活
        $art_list[1] = $document->join("ot_document_merchant on ot_document.id =ot_document_merchant.id")->field("ot_document.id,ot_document.title,ot_document.cover_id,ot_document.category_id,ot_document.create_time")->where($ho_map)->limit(3)->order("level desc,id desc")->select();//社区活动
        $art_list[2] = $document->join("ot_document_article on ot_document.id =ot_document_article.id")->field("ot_document.id,ot_document.title,ot_document.cover_id,ot_document.category_id,ot_document.create_time")->where($shop_map)->limit(3)->order("level desc,id desc")->select();//商品
        $this->assign("art_list",$art_list);
        $this->display();
    }

}